'use strict';

exports.__esModule = true;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _button = require('antd/lib/button');

var _button2 = _interopRequireDefault(_button);

var _modal = require('antd/lib/modal');

var _modal2 = _interopRequireDefault(_modal);

var _utils = require('../../libs/utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var ErrorModal = function (_Component) {
  (0, _inherits3.default)(ErrorModal, _Component);

  function ErrorModal() {
    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, ErrorModal);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
      show: false
    }, _this.onClose = function () {
      _this.setState({
        show: false
      });

      _this.modal.box.addEventListener('transitionend', function () {
        _this.props.onClose();
      });
    }, _this.bindModalRef = function (ref) {
      _this.modal = ref;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  ErrorModal.prototype.componentDidMount = function componentDidMount() {
    var _this2 = this;

    this.animationFrame = requestAnimationFrame(function () {
      _this2.setState({
        show: true
      });
    });
  };

  ErrorModal.prototype.componentWillUnmount = function componentWillUnmount() {
    cancelAnimationFrame(this.animationFrame);
  };

  ErrorModal.prototype.render = function render() {
    var error = this.props.error;
    var show = this.state.show;

    var errMsg = error;

    return _react2.default.createElement(
      _modal2.default,
      {
        ref: this.bindModalRef,
        title: 'Error',
        onClose: this.onClose,
        shown: show
      },
      _react2.default.createElement('div', {
        className: 'modal-body',
        dangerouslySetInnerHTML: { __html: '' + errMsg } // eslint-disable-line
      }),
      _react2.default.createElement(
        'div',
        { className: 'modal-footer' },
        _react2.default.createElement(
          _button2.default,
          { type: 'secondary', onClick: this.onClose, noSubmit: true },
          'Close'
        )
      )
    );
  };

  return ErrorModal;
}(_react.Component);

ErrorModal.propTypes = {
  onClose: _propTypes.func,
  error: _propTypes.string
};
ErrorModal.defaultProps = {
  onClose: _utils.noop,
  error: 'string'
};
exports.default = ErrorModal;